﻿using System.Windows;
using System.Reflection;
using System.Windows.Controls;

namespace Builderator.Firefly.Controls
{
    /// <summary>
    /// Interaction logic for TextControl.xaml
    /// </summary>
    public partial class TextControl : UserControl, IProperty
    {
        public static DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(TextControl));

        public new event PropertyChanged OnPropertyChanged;

        public bool IsReadyOnly
        {
            set
            {
                this.textTextBox.IsReadOnly = value;
            }
        }

        public string Text
        {
            get
            {
                return (string)GetValue(TextProperty);
            }
            set
            {
                SetValue(TextProperty, value);

                this.textTextBox.Text = value;

                if (this.OnPropertyChanged != null)
                    this.OnPropertyChanged(this.Property, GetValue(TextProperty));
            }
        }

        public PropertyInfo Property
        {
            get;
            set;
        }

        private TextControl()
        {
            InitializeComponent();
        }

        public TextControl(PropertyInfo property)
            : this()
        {
            this.Property = property;
        }

        private void textTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.Text = textTextBox.Text;
        }
    }
}
